home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / masm.arc / HELLO.ASM < prev    next >
Assembly Source File  |  1985-03-06  |  3KB  |  81 lines

  1.          name      hello
  2.          page      55,132
  3.          title     'HELLO --- print Hello on terminal'
  4. ;
  5. ; HELLO utility to demonstrate various parts
  6. ; of a functional assembly language program,
  7. ; use of segments, and a PC-DOS function call.
  8. ;
  9. ; Ray Duncan, September 1983
  10. ;
  11.                              ;show use of some EQUATES:
  12. cr       equ       0dh       ;ASCII carriage return
  13. lf       equ       0ah       ;ASCII line feed
  14.                              ;
  15. ;
  16.                              ;begin the "Code" segment
  17.                              ;containing executable
  18.                              ;machine code
  19. cseg     segment   para public 'CODE'
  20. ;
  21.          assume    cs:cseg,ds:dseg,ss:stack
  22. ;
  23. print    proc      far       ;actual program code
  24.                              ;is completely contained
  25.                              ;in the "procedure" named
  26.                              ;"PRINT".
  27.                              ;
  28.          push      ds        ;save DS:0000 on stack
  29.          xor       ax,ax     ;for final exit to PC-DOS.
  30.          push      ax
  31.                              ;set Data Segment Register
  32.                              ;to point to the Data Segment
  33.                              ;of this program, so that the
  34.                              ;message we want to print is
  35.                              ;addressable.
  36.          mov       ax,seg dseg
  37.          mov       ds,ax
  38.                              ;now put the offset of the
  39.                              ;message text into DX,
  40.          mov       dx,offset message
  41.                              ;now DS:DX specifies the
  42.                              ;full address of the message.
  43.          mov       ah,9      ;use the PC-DOS function 9
  44.          int       21h       ;to print the string.
  45.                              ;
  46.          ret                 ;now return to PC-DOS using
  47.                              ;the addresses we pushed on
  48.                              ;the stack at entry.
  49.                              ;
  50. print    endp                ;end of the "procedure"
  51.                              ;named "PRINT"
  52.                              ;
  53. cseg     ends                ;end of the code segment
  54.                              ;containing executable
  55.                              ;program.
  56.                              ;
  57.                              ;now we define a data segment
  58.                              ;containing our program's
  59.                              ;constants and variables.
  60. dseg     segment   para 'DATA'
  61.                              ;
  62. message  db        cr,lf,'Hello!',cr,lf,'$'
  63.                              ;
  64. dseg     ends
  65.                              ;
  66.                              ;lastly, we define a Stack
  67.                              ;Segment which contains
  68.                              ;a scratch area of memory
  69.                              ;for use by our program's stack
  70. stack    segment   para stack 'STACK'
  71.                              ;allow 64 bytes in this case
  72.          db        64 dup (?)
  73.                              ;
  74. stack    ends
  75.                              ;the final "End" statement
  76.                              ;signals the end of this
  77.                              ;program source file, and gives
  78.                              ;the starting address of
  79.                              ;the executable program
  80.          end       print
  81.